broadway: Detect binary websockets support
authorAlexander Larsson <alexl@redhat.com>
Mon, 1 Oct 2012 09:50:16 +0000 (11:50 +0200)
committerAlexander Larsson <alexl@redhat.com>
Mon, 1 Oct 2012 12:58:56 +0000 (14:58 +0200)
gdk/broadway/broadway.js
gdk/broadway/gdkdisplay-broadway.c

index 86b605a50cca75b2bfaeffc001d7f8852733d4ee..a5e30c1bfddd96c4b3198ade87181897dcdff0df 100644 (file)
@@ -2755,6 +2755,18 @@ function setupDocument(document)
     }
 }
 
+function newWS(loc) {
+    var ws = null;
+    if ("WebSocket" in window) {
+       ws = new WebSocket(loc, "broadway");
+    } else if ("MozWebSocket" in window) { // Firefox 6
+       ws = new MozWebSocket(loc);
+    } else {
+       alert("WebSocket not supported, broadway will not work!");
+    }
+    return ws;
+}
+
 function connect()
 {
     var url = window.location.toString();
@@ -2767,15 +2779,13 @@ function connect()
 
     var loc = window.location.toString().replace("http:", "ws:");
     loc = loc.substr(0, loc.lastIndexOf('/')) + "/socket";
-    var ws = null;
 
-    if ("WebSocket" in window) {
-       ws = new WebSocket(loc, "broadway");
-    } else if ("MozWebSocket" in window) { // Firefox 6
-       ws = new MozWebSocket(loc);
+    var supports_binary = newWS (loc + "-test").binaryType == "blob";
+    if (supports_binary) {
+       ws = newWS (loc + "-bin");
+       ws.binaryType = "arraybuffer";
     } else {
-       alert("WebSocket not supported, input will not work!");
-       return;
+       ws = newWS (loc);
     }
 
        ws.onopen = function() {
index 49d95a27402722ddd3e1e9ca5bfc3f464f3e701b..a6fadd604b5c211b5cc9a661f996cd0aefa65eb4 100644 (file)
@@ -149,6 +149,7 @@ struct BroadwayInput {
   gboolean seen_time;
   gint64 time_base;
   gboolean proto_v7_plus;
+  gboolean binary;
 };
 
 static void
@@ -691,7 +692,7 @@ generate_handshake_response_wsietf_v7 (const gchar *key)
 }
 
 static void
-start_input (HttpRequest *request)
+start_input (HttpRequest *request, gboolean binary)
 {
   char **lines;
   char *p;
@@ -867,6 +868,7 @@ start_input (HttpRequest *request)
   input->display = request->display;
   input->connection = g_object_ref (request->connection);
   input->proto_v7_plus = proto_v7_plus;
+  input->binary = binary;
 
   data_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (request->data), &data_buffer_size);
   input->buffer = g_byte_array_sized_new (data_buffer_size);
@@ -985,7 +987,9 @@ got_request (HttpRequest *request)
   else if (strcmp (escaped, "/broadway.js") == 0)
     send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1);
   else if (strcmp (escaped, "/socket") == 0)
-    start_input (request);
+    start_input (request, FALSE);
+  else if (strcmp (escaped, "/socket-bin") == 0)
+    start_input (request, TRUE);
   else
     send_error (request, 404, "File not found");